﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNet.Practico1.DataAccess;

namespace DotNet.Practico1.UI.Presentation
{
    public class GroupsPresenter
    {
        protected IGroupsView _view;

        public GroupsPresenter(IGroupsView view)
        {
            this._view = view;
        }

        public void Save()
        {
            using (var data = new DotNetPractico1Entities())
            {
                Group grp = new Group();
                if (this._view.GroupId != -1)
                {
                    grp = (from g in data.Groups
                           where g.Id == this._view.GroupId
                           select g).Single();
                }
                grp.Name = this._view.GroupName;

                if (this._view.GroupId == -1)
                    data.Groups.AddObject(grp);

                data.SaveChanges();
            }

        }
    }
}
